<template>
	<view class="order">
			<!-- 地址 -->
				<view  @click="navAddress" class="address-section">
					<view class="order-content">
						<text class="yticon icon-shouhuodizhi"></text>
						<block v-if="userAdds.length>0">
						<view class="cen">
							<view class="top">
								<text class="name">{{paymentAdds.name}}</text>
								<text class="mobile">{{paymentAdds.mobile}}</text>
							</view>
							<text class="address">{{paymentAdds.address}} {{paymentAdds.area}}</text>
						</view>
						
						</block>
						<text v-else style="color: red; margin-right: 100rpx;">还没有收货地址，赶紧去编辑吧</text>
						<text class="yticon icon-you"></text>
					</view>
					<!-- //图片分割线 -->
					<image class="a-bg" src=""></image>
				</view>
				<!-- // 店铺，商品 -->
				<block v-for="(item,index) in sameitems" :key='index'>
						<GoodShop :shop_goods='item'></GoodShop>
				</block>
				
					
					
		<!-- 优惠明细 -->
		<view class="yt-list">
			<view class="yt-list-cell b-b" @click="toggleMask('show')">
				<view class="cell-icon">
					券
				</view>
				<text class="cell-tit clamp">优惠券</text>
				<text class="cell-tip active">
					选择优惠券
				</text>
				<text class="cell-more wanjia wanjia-gengduo-d"></text>
			</view>
			<view class="yt-list-cell b-b">
				<view class="cell-icon hb">
					减
				</view>
				<text class="cell-tit clamp">商家促销</text>
				<text class="cell-tip disabled">暂无可用优惠</text>
			</view>
		</view>
		<ListColumn v-model='inpValue' :buymoney='or.originalprice' :discount='or.discount'></ListColumn>
		<view class="block-botten"></view>
		<!-- 底部 -->
		<view class="footer">
			<view class="price-content">
				<text>实付款</text>
				<text class="price-tip">￥</text>
				<text class="price">{{or.buyMoney}}</text>
			</view>
			<text class="submit" @click="submit">提交订单</text>
		</view>
		
		<!-- 优惠劵 -->
		<Coupon @close='toggleMask' :maskState='maskState'></Coupon>		
	</view>
</template>

<script>
	import GoodShop from '../../component/commont/GoodShop.vue'
	import Coupon from '../../component/commont/Coupon.vue'
	import ListColumn from '../../component/commont/ListColumn.vue'
	import {
		mapState,
		mapMutations,
		mapGetters,
		mapActions
	} from 'vuex';
	export default {
		components:{
			GoodShop,
			Coupon,
			ListColumn
		},
		computed:{
			...mapState({
				sameitems:state=>state.cat.sameitems,
				paymentAdds:state=>state.user.paymentAdds,// 获取默认地址
				userAdds:state=>state.user.userAdds
			})
			
		},
		data() {
			return {
				inpValue:'',
				maskState:0,
				or:{
					buyMoney:0,
					discount:0,
					originalprice:0
				}
			}
		},
		onShow() {
			console.log(this.paymentAdds)
		},
		onLoad(options) {
			// 获取地址
			this.getAdds()
			// console.log(options)
			// console.log('xuan',this.sameitems)
			this.getMoney()
		},
		onUnload(){
			// 离开页面， 清空掉 付款车中的数据
			this.delsameitems()
			
		},
		methods: {
			...mapMutations(['delsameitems','remoeItem','setPaymentAdds','setAddPitch']),
			toggleMask(type){
				let timer = type=== 'show' ? 10 : 300;
				let	state = type === 'show' ? 1 : 0;
				this.maskState = 2;
				setTimeout(()=>{
					this.maskState = state;
				}, timer)
			},
			// 获取地址
			getAdds(){
				// 有后台,改成请求获取
				this.userAdds.some(res=>{
					if (res.default){
						this.setPaymentAdds(res)
					}
				})
				
			},
			
			submit(){
				if (JSON.stringify(this.paymentAdds) === '{}'){
					this.$api.msg('请先添加收货地址哦！！！')
					return
				}
				// 获取备注信息
				console.log(this.inpValue)
				this.remoeItem()
				// 跳转支付页面
				uni.redirectTo({
					url:'../../myInfo/payment/payment'
				})
			},
			// 获取商品价格
			getMoney(){
				this.sameitems.forEach(res=>{
					res.gooddata.forEach(j=>{
						this.or.originalprice  += Number(j.itemprice) * Number(j.shopNumber)
						this.or.buyMoney += j.itemendprice * Number(j.shopNumber)
					})
				})
				this.or.originalprice = this.or.originalprice.toFixed(2)
				this.or.buyMoney = this.or.buyMoney.toFixed(2)
				this.or.discount = (this.or.originalprice -this.or.buyMoney).toFixed(2)
			},
			navAddress(){
				this.setAddPitch(true)
				uni.navigateTo({
					url:'../../myInfo/my-address/my-address'
				})
			}
			
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background: $page-color-base;
		padding-bottom: 100upx;
	}
	.address-section {
		padding: 30upx 0;
		background: #fff;
		position: relative;

		.order-content {
			display: flex;
			
			align-items: center;
		}

		.icon-shouhuodizhi {
			flex-shrink: 0;
			display: flex;
			align-items: center;
			justify-content: center;
			width: 90upx;
			color: #888;
			font-size: 44upx;
		}

		.cen {
			display: flex;
			flex-direction: column;
			flex: 1;
			font-size: 28upx;
			color: $font-color-dark;
		}

		.name {
			font-size: 34upx;
			margin-right: 24upx;
		}

		.address {
			margin-top: 16upx;
			margin-right: 20upx;
			color: $font-color-light;
		}

		.icon-you {
			font-size: 32upx;
			color: $font-color-light;
			margin-right: 30upx;
		}

		.a-bg {
			position: absolute;
			left: 0;
			bottom: 0;
			display: block;
			width: 100%;
			height: 5upx;
		}
	}

// <!-- 优惠明细 -->
	.yt-list {
		margin-top: 5upx;
		background: #fff;
		// margin-bottom: 90upx;
	}
	.yt-list-cell {
		display: flex;
		align-items: center;
		padding: 10upx 30upx 10upx 40upx;
		line-height: 70upx;
		position: relative;

		&.cell-hover {
			background: #fafafa;
		}

		&.b-b:after {
			left: 30upx;
		}

		.cell-icon {
			height: 32upx;
			width: 32upx;
			font-size: 22upx;
			color: #fff;
			text-align: center;
			line-height: 32upx;
			background: #f85e52;
			border-radius: 4upx;
			margin-right: 12upx;

			&.hb {
				background: #ffaa0e;
			}

			&.lpk {
				background: #3ab54a;
			}

		}

		.cell-more {
			align-self: center;
			font-size: 24upx;
			color: $font-color-light;
			margin-left: 8upx;
			margin-right: -10upx;
		}

		.cell-tit {
			flex: 1;
			font-size: 26upx;
			color: $font-color-light;
			margin-right: 10upx;
		}

		.cell-tip {
			font-size: 26upx;
			color: $font-color-dark;

			&.disabled {
				color: $font-color-light;
			}

			&.active {
				color: $base-color;
			}
			&.red{
				color: $base-color;
			}
		}

		&.desc-cell {
			.cell-tit {
				max-width: 90upx;
			}
		}

		.desc {
			flex: 1;
			font-size: $font-base;
			color: $font-color-dark;
		}
	}

.block-botten{
	height: 90upx;
	width: 100%;
}

// 底部
	.footer{
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 995;
		display: flex;
		align-items: center;
		width: 100%;
		height: 90upx;
		justify-content: space-between;
		font-size: 30upx;
		background-color: #fff;
		z-index: 998;
		color: $font-color-base;
		box-shadow: 0 -1px 5px rgba(0,0,0,.1);
		.price-content{
			padding-left: 30upx;
		}
		.price-tip{
			color: $base-color;
			margin-left: 8upx;
		}
		.price{
			font-size: 36upx;
			color: $base-color;
		}
		.submit{
			display:flex;
			align-items:center;
			justify-content: center;
			width: 280upx;
			height: 100%;
			color: #fff;
			font-size: 32upx;
			background-color: $base-color;
		}
	}
</style>
